﻿using VideoServices.Domain.Entities;
using System.Linq;

namespace VideoServices.Domain.DAL
{
    public interface ICustomerDataAccess
    {
        /// <summary>
        /// Gets the customer by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        Customer GetCustomerById(int id);

        /// <summary>
        /// Creates the customer.
        /// </summary>
        /// <param name="newCustomer">The new customer.</param>
        /// <returns></returns>
        Customer CreateCustomer(Customer newCustomer);
    }

    public class CustomerDataAccess : BaseDataAccess, ICustomerDataAccess
    {
        #region Implementation of ICustomerDataAccess

        /// <summary>
        /// Gets the customer by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Customer GetCustomerById(int id)
        {
            Customer customer = DataContext.Customers.SingleOrDefault(c => c.id == id);
            return customer;
        }

        /// <summary>
        /// Creates the customer.
        /// </summary>
        /// <param name="newCustomer">The new customer.</param>
        /// <returns></returns>
        public Customer CreateCustomer(Customer newCustomer)
        {
            DataContext.Customers.InsertOnSubmit(newCustomer);
            DataContext.SubmitChanges();
            return newCustomer;
        }

        #endregion
    }
}
